﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class BaoMing : System.Web.UI.PageEx
{
    private DataSet ds = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!DalEx.DbSystemEx.ReadBaoMingState())
        {
            Response.Redirect("404.aspx");
        }
        if (!Page.IsPostBack)
        {
            DataBinds();
        }
    }
    protected static string displayBtn = " style=\"display:none;\"";
    private void DataBinds()
    {
        displayBtn = " style=\"display:none;\"";
        ds = DalEx.DbCompInfoEx.Select(" and cStatus=1");
        rptType.DataSource = ds;
        rptType.DataBind();

        Model.DbCompInfo dbCompInfo = DalEx.DbCompInfoEx.GetModel("BaoMing");
        this.lblShowTitle.Text = "龙岗区机关幼儿园本部";
        this.Signning.HRef = "Signning.aspx";
        try
        {
            if (base.Request.QueryString["F"].ToString() == "1")
            {
                dbCompInfo = DalEx.DbCompInfoEx.GetModel("BaoMing1");
                this.lblShowTitle.Text = "龙岗区机关幼儿园龙城分园";
                this.Signning.HRef = "Signning.aspx?F=1";
            }
            if (base.Request.QueryString["F"].ToString() == "2")
            {
                dbCompInfo = DalEx.DbCompInfoEx.GetModel("BaoMing2");
                this.lblShowTitle.Text = "龙岗区机关幼儿园南湾分园";
                this.Signning.HRef = "Signning.aspx?F=2";
            }
            if (base.Request.QueryString["F"].ToString() == "3")
            {
                dbCompInfo = DalEx.DbCompInfoEx.GetModel("BaoMing3");
                this.lblShowTitle.Text = "龙岗区机关幼儿园坂田分园";
                this.Signning.HRef = "Signning.aspx?F=3";
            }
        }
        catch
        {
        }
        if (dbCompInfo != null)
        {
            lblSubTitle.Text = lblShowTitle.Text = dbCompInfo.CName;
            litShowInfo.Text = HttpUtility.HtmlDecode(dbCompInfo.CNotes);
            lblEndDate.Text = dbCompInfo.CEndDate.ToString("yyyy/MM/dd HH:mm:ss");

            if (DateTime.Now >= dbCompInfo.CStaDate && DateTime.Now <= dbCompInfo.CEndDate)
            {
                displayBtn = "";
            }

            //lblEndDate.Visible = dbCompInfo.CEndDate.CompareTo(DateTime.Now) >= 0;
            pnlLinkSign.Visible = dbCompInfo.CEndDate.CompareTo(DateTime.Now) >= 0 || dbCompInfo.CEndDate.CompareTo(SqlHelper.MinDate) == 0;
            setMeta(dbCompInfo.CName, dbCompInfo.CKeywords, dbCompInfo.CDescription);
        }
    }
    protected Int64 GetEndSecond()
    {
        Int64 iSecond = 0;
        DateTime dtEndDate = SqlHelper.MinDate;
        if (!string.IsNullOrEmpty(lblEndDate.Text))
            DateTime.TryParse(lblEndDate.Text, out dtEndDate);
        iSecond = dtEndDate.Ticks / 1000000000;
        return iSecond;
    }
    private void setMeta(string title, string key, string des)
    {
        string strWebTitle = string.Empty, strWebKeywords = string.Empty, strWebDescription = string.Empty;
        Model.DbSystem dbSystem = Dal.DbSystemDal.Select(1);
        if (dbSystem != null)
        {
            strWebTitle = dbSystem.STitle;
            strWebKeywords = dbSystem.SKeywords;
            strWebDescription = dbSystem.SDescription;
        }
        HtmlMeta keywords = new HtmlMeta(); // keywords
        HtmlMeta description = new HtmlMeta(); // description
        keywords.Name = "keywords";
        keywords.Content = string.IsNullOrEmpty(key) ? strWebKeywords : key;

        this.Title = string.IsNullOrEmpty(title) ? strWebTitle : title;

        description.Name = "description";
        description.Content = string.IsNullOrEmpty(des) ? strWebDescription : des;

        Page.Header.Controls.Add(keywords);
        Page.Header.Controls.Add(description);
    }
}
